
//引入querystring模块
const qs = require("querystring");

let query = "wd=&from=pc_web&rf=3&hisdata=%5B%7B%22time%22%3A1531297255%2C%22kw%22%3A%22%E7%9F%A5%E4%B9%8E%22%7D%2C%7B%22time%22%3A1531323798%2C%22kw%22%3A%22solid%22%7D%2C%7B%22time%22%3A1531401988%2C%22kw%22%3A%22jq%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6%22%7D%2C%7B%22time%22%3A1531403256%2C%22kw%22%3A%22uncaught%20syntaxerror%3A%20unexpected%20token%22%7D%2C%7B%22time%22%3A1531409488%2C%22kw%22%3A%22%E6%B5%AE%E5%8A%A8%E7%9A%84%E6%97%B6%E5%80%99%E4%BC%9A%E8%B7%B3%E5%88%B0%E4%B8%8B%E4%B8%80%E8%A1%8C%22%7D%2C%7B%22time%22%3A1531486598%2C%22kw%22%3A%22jq%E6%8F%92%E4%BB%B6%22%7D%2C%7B%22time%22%3A1531548446%2C%22kw%22%3A%22require%22%7D%2C%7B%22time%22%3A1531548909%2C%22kw%22%3A%22require%E6%95%99%E7%A8%8B%22%7D%2C%7B%22time%22%3A1531551090%2C%22kw%22%3A%22git%20%E5%B7%A5%E4%BD%9C%E5%8C%BA%20%E6%9A%82%E5%AD%98%E5%8C%BA%20%E7%89%88%E6%9C%AC%E5%8C%BA%22%7D%5D&json=1&p=3&sid=1431_26910_21095&req=2&csor=0&cb=jQuery110209795273279203811_1532255936488&_=1532255936489";

//解析参数，path里?后面的参数
let result = qs.parse(query);

console.log(result)

/*
{ wd: '',
  from: 'pc_web',
  rf: '3',
  hisdata: '[{"time":1531297255,"kw":"知乎"},{"time":1531323798,"kw":"solid"},{"
time":1531401988,"kw":"jq点击事件"},{"time":1531403256,"kw":"uncaught syntaxerro
r: unexpected token"},{"time":1531409488,"kw":"浮动的时候会跳到下一行"},{"time":
1531486598,"kw":"jq插件"},{"time":1531548446,"kw":"require"},{"time":1531548909,
"kw":"require教程"},{"time":1531551090,"kw":"git 工作区 暂存区 版本区"}]',
  json: '1',
  p: '3',
  sid: '1431_26910_21095',
  req: '2',
  csor: '0',
  cb: 'jQuery110209795273279203811_1532255936488',
  _: '1532255936489' }
*/

//组装url参数字符串
let queryobj = {
    name:"张三",
    password:"123456",
    likes:["女","球","片"]
}
let result1 = qs.stringify(queryobj);
console.log(result1)
//name=%E5%BC%A0%E4%B8%89&password=123456&likes=%E5%A5%B3&likes=%E7%90%83&likes=%E7%89%87

//对中文字符串进行解码
let words = "呆儿，爱你哦！";
let result2 = qs.escape(words);
console.log(result2)

let words1 = "%E5%91%86%E5%84%BF%EF%BC%8C%E7%88%B1%E4%BD%A0%E5%93%A6%EF%BC%81";
let result3 = qs.unescape(words1);
console.log(result3)